/* author: Mariana Horita
   mariana.horita@gmail.com
   file: A4E1.cs*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Resolucao
{
    public partial class A4E1 : Form
    {
        public A4E1()
        {
            InitializeComponent();
        }

        private void A4E1_Load(object sender, EventArgs e)
        {
            if (MessageBox.Show("Desja carregar arquivo?", "Abir", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Abrir();
            }
        }

        private void A4E1_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (MessageBox.Show("Deseja salvar?", "Salvar", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Salvar();
            }
        }

        private void Abrir()
        {
            if (ofdArquivo.ShowDialog() == DialogResult.OK && ofdArquivo.FileName.Length > 0)
            {

                StreamReader sr;

                sr = new StreamReader(ofdArquivo.FileName);

                txtConteudo.Text = sr.ReadToEnd();

                sr.Close();
            }
        }

        private void Salvar()
        {
            if (sfdArquivo.ShowDialog() == DialogResult.OK && sfdArquivo.FileName.Length > 0)
            {

                StreamWriter sw;

                sw = new StreamWriter(sfdArquivo.FileName);

                sw.WriteLine(txtConteudo.Text);

                sw.Close();
            }
        }

        private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Abrir();
        }

        private void salvarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Salvar();
        }
    }
}
